package cn.com.bluemoon.daps.sync.core.sync.sql;

/**
 * @author Jarod.Kong
 * @date 2021-06-06 10:58
 **/
public class SqlStrBuilder implements IConstants {

    private final StringBuilder sb;

    public SqlStrBuilder() {
        sb = new StringBuilder();
    }

    public SqlStrBuilder appendSQ(String str){
        sb.append(SINGLE_QUOTE).append(str).append(SINGLE_QUOTE);
        return this;
    }

    public SqlStrBuilder appendNullToEmpty(Object obj) {
        if (obj == null) {
            obj = "";
        }
        append(obj);
        return this;
    }

    public SqlStrBuilder append(Object obj) {
        sb.append(obj);
        return this;
    }

    /**
     * 尾部分号
     * @return
     */
    public SqlStrBuilder appendSemc(String str){
        sb.append(SEMICOLON).append(str).append(SEMICOLON);
        return this;
    }

    /**
     * 尾部分号
     * @return
     */
    public SqlStrBuilder appendSemc(){
        sb.append(SEMICOLON);
        return this;
    }

    public SqlStrBuilder appendDQ(String str){
        sb.append(DOUBLE_QUOTE).append(str).append(DOUBLE_QUOTE);
        return this;
    }

    public SqlStrBuilder append(String str) {
        sb.append(str);
        return this;
    }

    public SqlStrBuilder appendBQ(String name) {
        sb.append(BLACK_QUOTE).append(name).append(BLACK_QUOTE);
        return this;
    }

    public SqlStrBuilder appendWS(String str) {
        sb.append(WHITE_SPACE).append(str).append(WHITE_SPACE);
        return this;
    }

    public SqlStrBuilder appendParen(String str) {
        sb.append(OPEN_PAREN).append(str).append(CLOSE_PAREN);
        return this;
    }

    public SqlStrBuilder appendLine(String str) {
        sb.append(str).append(System.lineSeparator());
        return this;
    }

    public SqlStrBuilder appendLine() {
        sb.append(System.lineSeparator());
        return this;
    }

    @Override
    public String toString() {
        return sb.toString();
    }

    public SqlStrBuilder appendWs() {
        sb.append(WHITE_SPACE);
        return this;
    }
}
